package com.cskaoyan.service.wx.impl;

import com.cskaoyan.bean.BasePageInfo;
import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.MarketBrandExample;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.service.wx.WXBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :rain
 * @description
 * @since 2022/06/28 19:25
 */
@Service
public class WXBrandServiceImpl implements WXBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    //获取商品的品牌信息
    @Override
    public CommonData<MarketBrand> queryAllInfo(BasePageInfo info) {
        //开启分页
        PageHelper.startPage(info.getPage(),info.getLimit());

        MarketBrandExample marketBrandExample = new MarketBrandExample();
        MarketBrandExample.Criteria criteria = marketBrandExample.createCriteria();
        //默认显示的是deleted为false的信息
        criteria.andDeletedEqualTo(false);
        List<MarketBrand> marketBrandList = marketBrandMapper.selectByExample(marketBrandExample);
        PageInfo<MarketBrand> pageInfo = new PageInfo<>(marketBrandList);
        return CommonData.data(pageInfo);
    }

    //通过id获取当前的品牌
    @Override
    public MarketBrand queryDetailInfo(Integer id) {
        //通过id获取当品牌的对象
        MarketBrand brand = marketBrandMapper.selectByPrimaryKey(id);
        return brand;
    }
}
